//
//  RxTableViewController.swift
//  RXSwiftTest
//
//  Created by ZhangBo on 2019/4/14.
//  Copyright © 2019 ZhangBo. All rights reserved.
//

import UIKit


class RxTableViewController1: UITableViewController {

    let reuserId: String = "cell"//重用标识
    let vcNames = [
        "RxViewController1",
        "RxViewController2",
        "RxViewController3",
        "RxViewController4",
        "RxViewController5",
        "RxViewController6",
    ]
    let items = [
        "01 RxSwift基本流程",
        "02 RxSwift基本框架初体验",
        "03 RxSwift在TableView中RX",
        "04 RxDataSource",
        "05 RxSwift封装网络",
        "06 RxSwift绑定ui和viewmodel"
    ]

    override func viewDidLoad() {
        super.viewDidLoad()
        //创建一个重用的单元格
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: reuserId)
    }

    // MARK: - Table view data source

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.vcNames.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: reuserId, for: indexPath)
        let model = self.items[indexPath.row]
        cell.textLabel?.text = model
        return cell
    }

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let row = indexPath.row
        guard let vc = getClass(stringName: (self.vcNames[row])) else {
            return
        }
        self.navigationController?.pushViewController(vc, animated: true)
    }

}
